package com.http;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;

import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;
import com.common.method.ServerPath;

/**
 * 
 * @ClassName:JobRleaseTask
 * @Description:TODO发布招聘
 * @author zhuw
 * @date 2013-8-17 下午2:18:35
 */
public class JobRleaseTask extends AsyncTask<Object, Void, ResultString> {
	public static interface CallBack extends NetWorkCallBack {
		/**
		 * 
		 * @Description:TODO处理底层获取后的数据
		 * @param result
		 * @return void
		 * @author zhuw
		 * @date 2013-4-24 上午10:19:30
		 */
		public abstract void procJobRelease(String msg);

	}

	CallBack callback;

	public JobRleaseTask(CallBack callback) {
		super();
		this.callback = callback;
	}

	@Override
	protected ResultString doInBackground(Object... params) {
		ResultString data = null;
		try {
			HashMap<String, Object> map = (HashMap<String, Object>)params[0];
			ArrayList<NameValuePair> paramPairs = new ArrayList<NameValuePair>();
			if (map != null && !map.isEmpty()) {
				for (Map.Entry<String, Object> entry : map.entrySet()) {
							paramPairs.add(new BasicNameValuePair(entry.getKey(),
									entry.getValue().toString()));
				}
			}
//			ArrayList<NameValuePair> paramPairs=new ArrayList<NameValuePair>();
//			
//			paramPairs.add(new BasicNameValuePair("User", params[0]));
//			paramPairs.add(new BasicNameValuePair("title", params[1]));
//			paramPairs.add(new BasicNameValuePair("description", params[2]));
//			paramPairs.add(new BasicNameValuePair("demand", params[3]));
//			paramPairs.add(new BasicNameValuePair("pay", params[4]));
//			paramPairs.add(new BasicNameValuePair("deadline", params[5]));
//			paramPairs.add(new BasicNameValuePair("cat", params[6]));
//			paramPairs.add(new BasicNameValuePair("skillStr", params[7]));
//			paramPairs.add(new BasicNameValuePair("points", params[8]));
			ResEntity re=NetConUtil.postByForm(ServerPath.JOB_RELEASE_PATH,paramPairs);
			if(re.code==ResEntity.S_OK){
//				User user=JsonUtil.parseUser(new JSONObject(re.jsonStr));
//			    data= new ResultString(CommonData.H_FLAG_SUCCESS, null, user);
				  data= new ResultString(CommonData.H_FLAG_SUCCESS,null, "发布成功");

			}else if(re.code==ResEntity.S_FAILED){
				
				  data= new ResultString(CommonData.H_FLAG_ERROR, "code:"+re.code+"    "+re.jsonStr, null);
				
			}else{
				  data= new ResultString(CommonData.H_FLAG_ERROR, "code:"+re.code+ErrorCode.ERROR_MSG, null);
			}
		} catch (Exception e) {
			data= new ResultString(CommonData.H_FLAG_ERROR, ErrorCode.ERROR_MSG, null);
			e.printStackTrace();

		}
		return data;
	}

	@Override
	protected void onPostExecute(ResultString result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callback.procJobRelease(result.result);

		} else {
			callback.procError(result.msg);
		}

	}
}
